Kameleon-Plus  0.3.2
FileReader.h
Go to the documentation of this file.
1 /*
2  * FileReader.h
3  *
4  * Created on: Apr 22, 2009
5  * Author: David Berrios
6  */
7 
8 #ifndef FILEREADER_H_
9 #define FILEREADER_H_
10 #include <string>
11 #include <vector>
12 #include <iostream>
13 #include "Attribute.h"
14 #include <boost/unordered_map.hpp>
15 #include "cdf.h"
16 
17 
18 
19 
20 
21 namespace ccmc
22 {
23 
24 
31  class FileReader
32  {
33 
34  public:
35 
36  FileReader();
37  long open(const std::string& filename, bool readonly = true);
38 
39  virtual std::vector<float>* getVariable(const std::string& variable) = 0;
40  virtual std::vector<float>* getVariable(long variableID) = 0;
41  virtual std::vector<float>* getVariable(const std::string& variable, long startIndex, long count) = 0;
42  virtual std::vector<float>* getVariable(long variableID, long startIndex, long count) = 0;
43  virtual float getVariableAtIndex(const std::string& variable, long index) = 0;
44  virtual float getVariableAtIndex(long variable_id, long index) = 0;
45  virtual std::vector<int>* getVariableInt(const std::string& variable) = 0;
46  virtual int getVariableIntAtIndex(const std::string& variable, long index) = 0;
47  virtual int getNumberOfGlobalAttributes() = 0;
48  virtual int getNumberOfVariables() = 0;
49  virtual int getNumberOfVariableAttributes() = 0;
50  virtual long getNumberOfRecords(const std::string& variable) = 0;
51  virtual long getNumberOfRecords(long variable_id) = 0;
52  virtual long getVariableID(const std::string& variable) = 0;
53  virtual std::string getVariableName(long variable_id) = 0;
54  virtual Attribute getGlobalAttribute(long i) = 0;
55  virtual std::string getGlobalAttributeName(long attribute_id) = 0;
56  virtual std::string getVariableAttributeName(long attribute_id) = 0;
57  virtual Attribute getGlobalAttribute(const std::string& attribute) = 0;
58  virtual long getGlobalAttributeID(const std::string& attribute) = 0;
59  virtual Attribute getVariableAttribute(const std::string& variable, const std::string& attribute) = 0;
60  virtual std::vector<std::string> getVariableAttributeNames() = 0;
61  virtual bool doesAttributeExist(const std::string& attribute) = 0;
62  virtual bool doesVariableExist(const std::string& variable) = 0;
63  void addVariableName(const std::string& variable, long id); //addVariableAttributes
64  long close();
65  virtual const std::string& getCurrentFilename() = 0;
66  virtual void initializeVariableIDs() = 0;
67  virtual void initializeVariableNames() = 0;
68  virtual long closeFile() = 0;
69  virtual long openFile(const std::string& filename, bool readonly) = 0;
70  virtual ~FileReader();
71 
72  static const long OK = 0L;
73  static const long OPEN_ERROR = -1L;
74  static const long FILE_DOES_NOT_EXIST = -2L;
75  static const long VARIABLE_DOES_NOT_EXIST = -3L;
76  static const long ATTRIBUTE_DOES_NOT_EXIST = -4L;
77  static const long LOAD_FAILED = -5L;
78  static const long UNABLE_TO_ALLOCATE_MEMORY = -6L;
79  static const long VARIABLE_NOT_IN_MEMORY = -7L;
80  static const long MODEL_NOT_SUPPORTED = -8L;
81  static const long NOT_A_VALID_KAMELEON_FILE = -9L;
82 
83  protected:
84  std::string current_filename;
87 
88 
89  boost::unordered_map<std::string, long> variableIDs;
90  boost::unordered_map<long, std::string> variableNames;
91  boost::unordered_map<std::string, Attribute> gAttributes;
92  boost::unordered_map<long, Attribute> gAttributeByID;
93  boost::unordered_map<std::string, boost::unordered_map<std::string, Attribute> > vAttributes;
96 
97 
98  };
99 }
100 
101 #endif /* FILEREADER_H_ */